import { lazy } from "react";

import AuthLayout from "../layouts/AuthLayout";
import MainLayout from "../layouts/MainLayout";
import NoMenuLayout from "../layouts/NoMenuLayout";
import exampleRoutes from "./routes/exampleRoutes"; // 引入动态生成的examples路由
import { RouteConfig, AppConfig } from "./types";

// 懒加载页面
const Login = lazy(() => import("../pages/Login"));
const NotFound = lazy(() => import("../pages/common/NotFound"));
const Unauthorized = lazy(() => import("../pages/common/Unauthorized"));
const DevelopmentNotice = lazy(
  () => import("../pages/admin/DevelopmentNotice")
);
const WelcomePage = lazy(() => import("../pages/welcome/WelcomePage"));
const SpaceList = lazy(() => import("../pages/space/SpaceList"));

const ExampleIndex = lazy(() => import("../pages/example/ExampleIndex")); // 添加示例索引页面
const AppIndex = lazy(() => import("../pages/app/AppIndex"));

// 应用配置
export const appConfig: AppConfig = {
  appName: "智能应用管理系统", // 原来是 "NB-AI 管理系统"
  defaultRoute: "/",
  unauthorizedRoute: "/unauthorized",
  loginRoute: "/login",
  notFoundRoute: "/404",
  routeMode: "browser",
};

// 路由配置
export const routes: RouteConfig[] = [
  // 主布局和受保护的路由
  {
    path: "/",
    component: MainLayout,
    isLayout: true,
    meta: {
      requiresAuth: true,
    },
    children: [
      {
        path: "",
        component: WelcomePage, // 将欢迎页设为首页
        meta: {
          title: "欢迎",
        },
      },
      {
        path: "home",
        component: DevelopmentNotice,
        meta: {
          title: "首页",
          icon: "🏠",
        },
      },
      {
        path: "create",
        component: DevelopmentNotice,
        meta: {
          title: "添加应用",
        },
      },
      {
        path: "space",
        component: SpaceList,
        meta: {
          title: "空间",
        },
      },
      {
        path: "market",
        component: DevelopmentNotice,
        meta: {
          title: "应用市场",
        },
      },
      // 示例索引页面
      {
        path: "example",
        component: ExampleIndex,
        meta: {
          title: "组件示例",
          icon: "Example",
        },
      },
      // 引入动态生成的examples路由
      ...exampleRoutes,
    ],
  },

  // 认证布局（无需认证的路由）
  {
    path: "/",
    component: AuthLayout,
    isLayout: true,
    children: [
      {
        path: "login",
        component: Login,
        meta: {
          title: "登录",
          requiresAuth: false,
          hideInMenu: true,
        },
      },
      {
        path: "unauthorized",
        component: Unauthorized,
        meta: {
          title: "无权限访问",
          requiresAuth: false,
          hideInMenu: true,
        },
      },
      {
        path: "*",
        component: NotFound,
        meta: {
          title: "页面不存在",
          requiresAuth: false,
          hideInMenu: true,
        },
      },
    ],
  },

  // 无菜单布局
  {
    path: "/",
    component: NoMenuLayout,
    isLayout: true,
    meta: {
      requiresAuth: true,
    },
    children: [
      {
        path: "app",
        component: AppIndex,
        meta: {
          title: "无菜单示例",
        },
      },
    ],
  },
];

export default routes;
